package com.cn.base;

//import com.mysql.jdbc.Connection;
import java.sql.Connection;//MySQL 8
import java.sql.DriverManager;
import java.sql.SQLException;

public class BaseDao {

    public static Connection getConn() {
        //String driver = "com.mysql.jdbc.Driver";
        String driver = "com.mysql.cj.jdbc.Driver";//MySQL 8
        String url = "jdbc:mysql://127.0.0.1:3306/baozhi?useUnicode=true&characterEncoding=UTF-8&serverTimezone=UTC";
        String username = "root";
        //String password = "admin";
        String password = "WAdl2020";
        Connection conn = null;
        try {
            Class.forName(driver); //classLoader,加载对应驱动
            conn = (Connection) DriverManager.getConnection(url, username, password);
            //  conn= (Connection) DriverManager.getConnection("jdbc:mysql://localhost/baozhi?serverTimezone=UTC+8","root","123456");
            System.out.println("连接成功");
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return conn;
    }
}